#!/usr/bin/python -tt
# -*- coding: utf-8 -*-

import sys
import os

def main():
  benchmark_folder = "."
  for f in os.listdir(benchmark_folder):
    if f.endswith('.linked.rbc'):
      benchmark_name = os.path.splitext(f)[0]
      os.system("rm *.log")
      logfile = open(benchmark_name + '.log', 'w+')
      logfile.write(benchmark_name + ':\n')
      opt_prefix = "opt -mem2reg -loop-simplify -load /home/douglas/llvm/Debug+Asserts/lib/LLVMIterationPredictor.so -iteration-predictor "
      opt_filename = benchmark_name + ".opt.bc"
      os.system(opt_prefix + f + " -o " + opt_filename + " -stats -debug")
      outfilename = benchmark_name + '.s'
      os.system('llc ' + opt_filename + ' -o ' + outfilename)
      os.system('g++ ' + outfilename + ' -o ' + benchmark_name)
      os.system('./' + benchmark_name + ' 2> ' + benchmark_name + '.log')
      logfile.close()    

if __name__ == '__main__':
  main()


